﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MaterialSkin.Controls;//MaterialSkin控件类库

namespace MotionGTS
{
    //MaterialForm是MaterialSkin库中的一个类，用于创建Material Design风格的窗体
    public partial class MainForm : MaterialForm
    {

        //运动控制的显示窗体
        private Frm_Show montionShow = null;

        public MainForm()
        {
            InitializeComponent();

            //加载运动控制窗体
            montionShow = new Frm_Show();
            //设置为非顶级窗体(不作为独立窗体显示，而是作为嵌入式窗体显示)
            montionShow.TopLevel = false;
            //设置填充满
            montionShow.Dock = DockStyle.Fill;
            //设置窗体停靠的TabPage页面
            montionShow.Parent = this.materialTabControl1.TabPages[0];
            //显示窗体
            montionShow.Show();

        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 窗体关闭前保存界面的位置与大小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            //保存窗体是否最大化
            INI.WritePrivateProfileString("窗体配置", "Maximized", this.WindowState == FormWindowState.Maximized ? "1" : "0", "./MainForm.ini");
            //保存窗体位置
            INI.WritePrivateProfileString("窗体配置", "LocationX", this.Location.X.ToString(), "./MainForm.ini");
            INI.WritePrivateProfileString("窗体配置", "LocationY", this.Location.Y.ToString(), "./MainForm.ini");
            //保存窗体大小
            INI.WritePrivateProfileString("窗体配置", "Width", this.Width.ToString(), "./MainForm.ini");
            INI.WritePrivateProfileString("窗体配置", "Height", this.Height.ToString(), "./MainForm.ini");

        }

        private void MainForm_Shown(object sender, EventArgs e)
        {
            //读取窗体位置与大小
            int x = int.Parse(INI.ContentValue("窗体配置", "LocationX", "./MainForm.ini"));
            int y = int.Parse(INI.ContentValue("窗体配置", "LocationY", "./MainForm.ini"));
            //读取窗体是否最大化
            int width = int.Parse(INI.ContentValue("窗体配置", "Width", "./MainForm.ini"));
            int height = int.Parse(INI.ContentValue("窗体配置", "Height", "./MainForm.ini"));
            //设置窗体位置
            this.Location = new Point(x, y);
            //设置窗体大小
            this.Width = width;
            this.Height = height;
            //设置窗体是否最大化
            if (INI.ContentValue("窗体配置", "Maximized", "./MainForm.ini") == "1")
            {
                this.WindowState = FormWindowState.Maximized;
            }
            else
            {
                this.WindowState = FormWindowState.Normal;
            }
        }
    }
}
